#include <iostream>
#include <stdio.h>

#include <iostream>
#include <memory>
#include <vector>
using namespace std;

class Solution
{
private:
    /* data */
public:
    int minSubArrayLen(int s, vector<int> & nums){
        int sum = 0;  //子序列和
        int start_index = 0; //子序列开始序列
        int result = INT32_MAX;  
        int subLen = 0; 

        for(int end_index = 0; end_index < nums.size(); end_index++){
            sum += nums[end_index];

            while(sum >= s){
                subLen = end_index - start_index + 1;
                result = (result < subLen)?result:subLen;
                sum -= nums[start_index++];
            }
        }

        return (result == INT32_MAX) ? 0 : result;
    }
};




int main(int argv, char**argc)
{

    printf("************  test hello zc!!!   **************\n");
    /* add test code! */
    vector<int> nums = {2,3,1,2,4,3};
    int s = 7;
    Solution solver;
    int ret = solver.minSubArrayLen(s, nums);

    printf("min sub len: %d", ret);


    return 0;
}
